#include "touchlineedit.h"
#include <QtGui>
#include "touchkeyboard.h"
#include <stdio.h>

TouchLineEdit::TouchLineEdit(QWidget *parent)
	: QLineEdit(parent),
	keyboard(0)
{
	
}

TouchLineEdit::~TouchLineEdit()
{
	if(keyboard){
		delete keyboard;
	}
}

void TouchLineEdit::focusInEvent(QFocusEvent *e)
{
	if(e->reason() == Qt::MouseFocusReason){
		callKeyboard();
	}
	QLineEdit::focusInEvent(e);
}

void TouchLineEdit::focusOutEvent(QFocusEvent *e)
{
	if(e->reason() == Qt::MouseFocusReason){
		releaseKeyboard();
	}
	QLineEdit::focusOutEvent(e);
}

void TouchLineEdit::callKeyboard()
{
	if(!keyboard){
		keyboard = new TouchKeyboard(this, nativeParentWidget());
		keyboard->move(0, 220);
		keyboard->show();
	}
}


void TouchLineEdit::releaseKeyboard()
{
	if(keyboard){
		delete keyboard;
		keyboard = 0;
	}
}
